use std::io::Read;
use std::net::TcpListener;
use std::thread::sleep;
use std::time::Duration;

mod thread_factory;


use crate::thread_factory::ThreadFactory;


fn main() {
    println!("{} http://127.0.0.1:8080", "Hiecho app is start");
    let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
    let threads = ThreadFactory::new(5);
    for x in listener.incoming().take(15) {
        let mut stream = x.unwrap();
        threads.exec(move || {
            let mut buf = [0; 1024];
            stream.read(&mut buf).unwrap();
            sleep(Duration::new(3,0));
            println!("{}", String::from_utf8_lossy(&buf));
        });
    }
}
